package com.example.demo.service.impl;

import com.example.demo.dao.UserRepository;
import com.example.demo.model.entity.UserModel;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserService {

    @Resource
    UserRepository userRepository;

    public UserModel getUserByUserName(String userName, Integer role) {
        return userRepository.findByUserNameAndRole(userName, role);
    }

    public UserModel save(UserModel model) {
        return userRepository.save(model);
    }

    public UserModel getByUid(String userId) {
        return userRepository.findOne(userId);
    }

    public Page<UserModel> findUserPage(Specification specification, Pageable pageable) {
        return userRepository.findAll(specification, pageable);
    }

    public void deleteUser(String userId) {
        userRepository.delete(userId);
    }
}
